<template>
  <view>
    <uni-easyinput v-model="echo" placeholder="要转md5的信息" />
    <button type="default" @click="send">md5</button>
    <view>{{ data }}</view>

  </view>

  <view class="">
    <button type="primary" @click="addCount">计数器+1</button>
    <view>{{ count }}</view>
  </view>

</template>

<script setup>
  import {
    Api
  } from '@/js/api.js'

  import {
    ref,
    onMounted
  } from 'vue'

  import {
    onLoad
  } from '@dcloudio/uni-app'

  const info = ref('api测试页')

  const echo = ref('')
  const data = ref('')

  const count = ref(0)

  const addCount = () => {
    Api.post(
      '/tools/counter/addNoLimit', {
        counterKey: 'huhuiyu_test_key'
      },
      (res) => {
        if (res.success) {
          count.value = res.data
          return
        }
        uni.showToast({
          title: res.message,
          icon: 'error'
        })
      }
    )
  }

  const send = () => {
    uni.showLoading({
      title: '加载中'
    })

    Api.get('/tools/md5', {
      info: echo.value
    }, (res) => {
      uni.hideLoading()

      if (res.success) {
        data.value = res.message
        return
      }
      uni.showToast({
        title: res.message,
        icon: 'error'
      })
    })
  }

  onLoad((options) => {
    console.log("api加载中。。。", options)
  })

  onMounted(() => {
    addCount()
  })
</script>

<style>

</style>